package remote;

import java.sql.*;
import java.rmi.*;
import java.util.Properties;

public class SimpleDriver extends DriverAdapter {

	static {
		try {
			DriverManager.registerDriver(new SimpleDriver());
		} catch (SQLException e) {}
	}

	public SimpleDriver() {}
	public Connection connect(String url, Properties prop) throws SQLException {
		try {
			System.out.println("Old: " + url);
			String newurl = url.replace("jdbc:fatworm", "rmi") + "fatworm";
			System.out.println("New: " + newurl);
			RemoteDriver rdvr = (RemoteDriver) Naming.lookup(newurl);
			RemoteConnection rconn = rdvr.connect();
			return new SimpleConnection(rconn);
		}
		catch (Exception e) {
			throw new SQLException(e);
		}
	}

	@Override
	public boolean acceptsURL(String url) throws SQLException {
		return true;
	}
}

